// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import FastClick from 'fastclick'
import App from './App'
import router from "./router/router.js"
import Vuex from 'vuex'
import CryptoJS from 'crypto-js';
import Jsonp from 'jsonp';




Vue.use(Vuex)


import {
  AjaxPlugin,
  ToastPlugin,
  WechatPlugin,
  AlertPlugin,
  DatetimePlugin
} from 'vux'
Vue.use(AjaxPlugin);
Vue.use(WechatPlugin);
Vue.use(AlertPlugin);
Vue.use(DatetimePlugin)

// 或者umd方式
// 引入构建的js文件

// 默认参数
Vue.use(ToastPlugin, {
  position: 'center'
})


// vuex

const state = {
  test: "test",
  name: "",
  defenseStatus: false
}

const mutations = {
  changeName(state, name) {
    state.name = name;
  },
  changeDefenseStatus(state,status){
    state.defenseStatus = status;
  }
}

const actions = {
  changeName({
    commit,
    state
  }, name) {

    //保存当前用户
    commit('changeName', name)
  },
  changeDefenseStatus({
    commit,
    state
  }, status) {

    //保存 当前 安防状态
    commit('changeDefenseStatus', status)
  }
}

const store = new Vuex.Store({
  state,
  actions,
  mutations
})






FastClick.attach(document.body)

Vue.config.productionTip = false;

Vue.prototype.$CryptoJS = CryptoJS;
Vue.prototype.$Jsonp = Jsonp;
Vue.prototype.$IsBind = function(falseCallBack, trueCallBack) {
  Vue.http.get("http://iot.malanco.com/myDevice").then(response => {
    if (response.data.success == "true") {
      var device = response.data.data;
      if (device == null ||
        device.deviceId == "" ||
        device.deviceId == null) {
        // 没有绑定
        falseCallBack();
      } else {
        trueCallBack();
      }
    }
  })
}

/* eslint-disable no-new */
new Vue({
  router,
  store,
  mounted: function() {
    //配置 微信 wx.config

    var urlValue = window.location.href.split('#')[0];


    this.$http.get('http://iot.malanco.com/getJsTicketSignuature', {params:{
      "url": urlValue
    }}).then(response => {
      console.log(response.data);
      console.log(response.data.appId);
      Vue.wechat.config({
        debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
        appId: response.data.appId, // 必填，公众号的唯一标识
        timestamp: response.data.timestamp, // 必填，生成签名的时间戳
        nonceStr: response.data.noncestr, // 必填，生成签名的随机串
        signature: response.data.signature, // 必填，签名，见附录1
        jsApiList: ['scanQRCode'] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
      })
      Vue.wechat.ready(function() {
        console.log('>>>>>>>>>>>>>>>>>>>>>222222222222')
      });
  }, error => {
      console.log(error);
  });
  },
  render: h => h(App)
}).$mount('#app-box')
